﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
using System.Collections.Generic;//Please add references
namespace ElingOA6_Admin_DSJCJ.DAL
{
	/// <summary>
	/// 数据访问类:chkInfoAuditManual
	/// </summary>
	public partial class ChkInfoAuditManual
	{
		public ChkInfoAuditManual()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string FEntityNo,string FInfoClsNo,decimal FYear,string FDeptNo,string FEmpNo,decimal FInfoID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from t_chkInfoAuditManual");
			strSql.Append(" where FEntityNo=@FEntityNo and FInfoClsNo=@FInfoClsNo and FYear=@FYear and FDeptNo=@FDeptNo and FEmpNo=@FEmpNo and FInfoID=@FInfoID ");
			SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInfoClsNo", SqlDbType.NVarChar,30),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FInfoID", SqlDbType.Decimal,9)			};
			parameters[0].Value = FEntityNo;
			parameters[1].Value = FInfoClsNo;
			parameters[2].Value = FYear;
			parameters[3].Value = FDeptNo;
			parameters[4].Value = FEmpNo;
			parameters[5].Value = FInfoID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}

        /// <summary>
        /// 获取所有的年份
        /// <creator>zhongyl</creator>
        /// <date>2013-10-16</date>
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <returns></returns>
        public DataSet GetYeat(string strEntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT FYear FROM [dbo].[t_chkInfoAuditManual] GROUP BY FYear");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50)};
            parameters[0].Value = strEntityNo;

            return DbHelperSQL.Query(strSql.ToString(), parameters);

        }


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public decimal Add(ElingOA6_Admin_DSJCJ.Model.ChkInfoAuditManual model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into t_chkInfoAuditManual(");
			strSql.Append("FEntityNo,FTitle,FAuditDate,FScore,FInfoMedia,FInfoClsNo,FYear,FAuditDeptNo,FAuditEmpNo,FDeptNo,FEmpNo,FPage,FNote)");
			strSql.Append(" values (");
			strSql.Append("@FEntityNo,@FTitle,@FAuditDate,@FScore,@FInfoMedia,@FInfoClsNo,@FYear,@FAuditDeptNo,@FAuditEmpNo,@FDeptNo,@FEmpNo,@FPage,@FNote)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FTitle", SqlDbType.NVarChar,20),
					new SqlParameter("@FAuditDate", SqlDbType.DateTime),
					new SqlParameter("@FScore", SqlDbType.Decimal,9),
					new SqlParameter("@FInfoMedia", SqlDbType.NVarChar,20),
					new SqlParameter("@FInfoClsNo", SqlDbType.NVarChar,30),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FAuditDeptNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FAuditEmpNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FPage", SqlDbType.NVarChar,20),
					new SqlParameter("@FNote", SqlDbType.NVarChar,20)};
			parameters[0].Value = model.FEntityNo;
			parameters[1].Value = model.FTitle;
			parameters[2].Value = model.FAuditDate;
			parameters[3].Value = model.FScore;
			parameters[4].Value = model.FInfoMedia;
			parameters[5].Value = model.FInfoClsNo;
			parameters[6].Value = model.FYear;
			parameters[7].Value = model.FAuditDeptNo;
			parameters[8].Value = model.FAuditEmpNo;
			parameters[9].Value = model.FDeptNo;
			parameters[10].Value = model.FEmpNo;
			parameters[11].Value = model.FPage;
			parameters[12].Value = model.FNote;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToDecimal(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ElingOA6_Admin_DSJCJ.Model.ChkInfoAuditManual model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update t_chkInfoAuditManual set ");
			strSql.Append("FTitle=@FTitle,");
			strSql.Append("FAuditDate=@FAuditDate,");
			strSql.Append("FScore=@FScore,");
			strSql.Append("FInfoMedia=@FInfoMedia,");
            strSql.Append("FInfoClsNo=@FInfoClsNo,");
            strSql.Append("FDeptNo=@FDeptNo,");
            strSql.Append("FEmpNo=@FEmpNo,");
			strSql.Append("FPage=@FPage,");
			strSql.Append("FNote=@FNote");
			strSql.Append(" where FInfoID=@FInfoID");
			SqlParameter[] parameters = {
					new SqlParameter("@FTitle", SqlDbType.NVarChar,20),
					new SqlParameter("@FAuditDate", SqlDbType.DateTime),
					new SqlParameter("@FScore", SqlDbType.Decimal,9),
					new SqlParameter("@FInfoMedia", SqlDbType.NVarChar,20),
					new SqlParameter("@FPage", SqlDbType.NVarChar,20),
					new SqlParameter("@FNote", SqlDbType.NVarChar,20),
					new SqlParameter("@FInfoID", SqlDbType.Decimal,9),
					new SqlParameter("@FInfoClsNo", SqlDbType.NVarChar,30),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmpNo", SqlDbType.NVarChar,15)};
			parameters[0].Value = model.FTitle;
			parameters[1].Value = model.FAuditDate;
			parameters[2].Value = model.FScore;
			parameters[3].Value = model.FInfoMedia;
			parameters[4].Value = model.FPage;
			parameters[5].Value = model.FNote;
			parameters[6].Value = model.FInfoID;
			parameters[7].Value = model.FInfoClsNo;
			parameters[8].Value = model.FDeptNo;
			parameters[9].Value = model.FEmpNo;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal FInfoID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from t_chkInfoAuditManual ");
			strSql.Append(" where FInfoID=@FInfoID");
			SqlParameter[] parameters = {
					new SqlParameter("@FInfoID", SqlDbType.Decimal)
			};
			parameters[0].Value = FInfoID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string FEntityNo,string FInfoClsNo,decimal FYear,string FDeptNo,string FEmpNo,decimal FInfoID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from t_chkInfoAuditManual ");
			strSql.Append(" where FEntityNo=@FEntityNo and FInfoClsNo=@FInfoClsNo and FYear=@FYear and FDeptNo=@FDeptNo and FEmpNo=@FEmpNo and FInfoID=@FInfoID ");
			SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FInfoClsNo", SqlDbType.NVarChar,30),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmpNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FInfoID", SqlDbType.Decimal,9)			};
			parameters[0].Value = FEntityNo;
			parameters[1].Value = FInfoClsNo;
			parameters[2].Value = FYear;
			parameters[3].Value = FDeptNo;
			parameters[4].Value = FEmpNo;
			parameters[5].Value = FInfoID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string FInfoIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from t_chkInfoAuditManual ");
            strSql.Append(" where FInfoID in (" + FInfoIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ElingOA6_Admin_DSJCJ.Model.ChkInfoAuditManual GetModel(decimal FInfoID)
		{
			
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 FInfoID,FEntityNo,FTitle,FAuditDate,FScore,FInfoMedia,FInfoClsNo,FYear,FAuditDeptNo,FAuditEmpNo,FDeptNo,FEmpNo,FPage,FNote,FDeptName,FEmpName from v_chkInfoAuditManual ");
			strSql.Append(" where FInfoID=@FInfoID");
			SqlParameter[] parameters = {
					new SqlParameter("@FInfoID", SqlDbType.Decimal)
			};
			parameters[0].Value = FInfoID;

			ElingOA6_Admin_DSJCJ.Model.ChkInfoAuditManual model=new ElingOA6_Admin_DSJCJ.Model.ChkInfoAuditManual();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select FInfoID,FEntityNo,FTitle,FAuditDate,FScore,FInfoMedia,FInfoClsNo,FYear,FAuditDeptNo,FAuditEmpNo,FDeptNo,FEmpNo,FPage,FNote ");
			strSql.Append(" FROM t_chkInfoAuditManual ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" FInfoID,FEntityNo,FTitle,FAuditDate,FScore,FInfoMedia,FInfoClsNo,FYear,FAuditDeptNo,FAuditEmpNo,FDeptNo,FEmpNo,FPage,FNote ");
			strSql.Append(" FROM t_chkInfoAuditManual ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM t_chkInfoAuditManual ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.FInfoID desc");
			}
			strSql.Append(")AS Row, T.*  from t_chkInfoAuditManual T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "t_chkInfoAuditManual";
			parameters[1].Value = "FInfoID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  已经使用过的
        /// <summary>
        /// 获取上级录用信息
        /// <creator>sunlj</creator>
        /// <date>2013-10-17</date>
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="decYear"></param>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListByYear(string strEntityNo, decimal decYear, string strWhere)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FInfoID,FEntityNo,FTitle,FAuditDate,FScore,FInfoMedia,FInfoClsNo,FYear,FAuditDeptNo,FAuditEmpNo,FDeptNo,FEmpNo,FPage,FNote from t_chkInfoAuditManual ");
            strSql.Append(" where FEntityNo=@FEntityNo and FYear=@FYear");
            if (strWhere != "")
            {
                strSql.Append(" and " + strWhere);
            }
            SqlParameter[] parameters = {
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FYear", SqlDbType.Decimal,5)
			};
            parameters[0].Value = strEntityNo;
            parameters[1].Value = decYear;
            Model.ChkInfoAuditManual model = new Model.ChkInfoAuditManual();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            return ds;
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>sunlj</creator>
        /// <date>2013-10-17</date>
        /// </summary>
        public ElingOA6_Admin_DSJCJ.Model.ChkInfoAuditManual DataRowToModel(DataRow row)
        {
            ElingOA6_Admin_DSJCJ.Model.ChkInfoAuditManual model = new ElingOA6_Admin_DSJCJ.Model.ChkInfoAuditManual();
            if (row != null)
            {
                if (row["FInfoID"] != null && row["FInfoID"].ToString() != "")
                {
                    model.FInfoID = decimal.Parse(row["FInfoID"].ToString());
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
                if (row["FTitle"] != null)
                {
                    model.FTitle = row["FTitle"].ToString();
                }
                if (row["FAuditDate"] != null && row["FAuditDate"].ToString() != "")
                {
                    model.FAuditDate = DateTime.Parse(row["FAuditDate"].ToString());
                }
                if (row["FScore"] != null && row["FScore"].ToString() != "")
                {
                    model.FScore = decimal.Parse(row["FScore"].ToString());
                }
                if (row["FInfoMedia"] != null)
                {
                    model.FInfoMedia = row["FInfoMedia"].ToString();
                }
                if (row["FInfoClsNo"] != null)
                {
                    model.FInfoClsNo = row["FInfoClsNo"].ToString();
                }
                if (row["FYear"] != null && row["FYear"].ToString() != "")
                {
                    model.FYear = decimal.Parse(row["FYear"].ToString());
                }
                if (row["FAuditDeptNo"] != null)
                {
                    model.FAuditDeptNo = row["FAuditDeptNo"].ToString();
                }
                if (row["FAuditEmpNo"] != null)
                {
                    model.FAuditEmpNo = row["FAuditEmpNo"].ToString();
                }
                if (row["FDeptNo"] != null)
                {
                    model.FDeptNo = row["FDeptNo"].ToString();
                }
                if (row["FEmpNo"] != null)
                {
                    model.FEmpNo = row["FEmpNo"].ToString();
                }
                if (row["FPage"] != null)
                {
                    model.FPage = row["FPage"].ToString();
                }
                if (row["FNote"] != null)
                {
                    model.FNote = row["FNote"].ToString();
                }

                if (row.Table.Columns.Contains("FDeptName"))
                {
                    if (row["FDeptName"] != null)
                    {
                        model.FDeptName = row["FDeptName"].ToString();
                    }
                }

                if (row.Table.Columns.Contains("FEmpName"))
                {
                    if (row["FEmpName"] != null)
                    {
                        model.FEmpName = row["FEmpName"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FScoreAll"))
                {
                    if (row["FScoreAll"] != null && row["FScoreAll"].ToString() != "")
                    {
                        model.FScoreAll = decimal.Parse(row["FScoreAll"].ToString());
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 获取上级录用信息
        /// <creator>sunlj</creator>
        /// <date>2013-10-19</date>
        /// </summary>
        /// <param name="strEntityNo"></param>
        /// <param name="deptNo"></param>
        /// <param name="decYear"></param>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListByYearAndDeptNo(string strEntityNo, string fDeptNo, decimal decYear, string strWhere)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FInfoID,FEntityNo,FTitle,FAuditDate,FScore,FInfoMedia,FInfoClsNo,FYear,FAuditDeptNo,FAuditEmpNo,FDeptNo,FEmpNo,FPage,FNote from t_chkInfoAuditManual ");
            strSql.Append(" where FEntityNo=@FEntityNo and FYear=@FYear and FDeptNo=@FDeptNo");
            if (strWhere != "")
            {
                strSql.Append(" and " + strWhere);
            }
            SqlParameter[] parameters = {
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FYear", SqlDbType.Decimal,5),
                    new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
			};
            parameters[0].Value = strEntityNo;
            parameters[1].Value = decYear;
            parameters[2].Value = fDeptNo;
            Model.ChkInfoAuditManual model = new Model.ChkInfoAuditManual();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            return ds;

        }

        #endregion  已经使用过的
    }
}

